package com.ruoyi.web.controller.system;

import java.util.List;

import com.ruoyi.system.domain.OldMan;
import com.ruoyi.system.service.IOldManService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.HealthProfile;
import com.ruoyi.system.service.IHealthProfileService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 健康档案Controller
 * 
 * @author 王帅
 * @date 2024-11-03
 */
@Controller
@RequestMapping("/system/profile")
public class HealthProfileController extends BaseController
{
    private String prefix = "system/profile";

    @Autowired
    private IHealthProfileService healthProfileService;
    @Autowired
    private IOldManService oldManService;


    @GetMapping()
    public String profile()
    {

        return prefix + "/profile";
    }

    /**
     * 查询健康档案列表
     */

    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HealthProfile healthProfile)
    {
        startPage();
        List<HealthProfile> list = healthProfileService.selectHealthProfileList(healthProfile);
        return getDataTable(list);
    }

    /**
     * 导出健康档案列表
     */

    @Log(title = "健康档案", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HealthProfile healthProfile)
    {
        List<HealthProfile> list = healthProfileService.selectHealthProfileList(healthProfile);
        ExcelUtil<HealthProfile> util = new ExcelUtil<HealthProfile>(HealthProfile.class);
        return util.exportExcel(list, "健康档案数据");
    }

    /**
     * 新增健康档案
     */
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        List<OldMan> oldMEN = oldManService.selectOldManList(new OldMan());
        mmap.put("olds",oldMEN);
        return prefix + "/add";
    }

    /**
     * 新增保存健康档案
     */
    @Log(title = "健康档案", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HealthProfile healthProfile)
    {
        return toAjax(healthProfileService.insertHealthProfile(healthProfile));
    }

    /**
     * 修改健康档案
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HealthProfile healthProfile = healthProfileService.selectHealthProfileById(id);
        List<OldMan> oldMEN = oldManService.selectOldManList(new OldMan());
        mmap.put("olds",oldMEN);
        mmap.put("healthProfile", healthProfile);
        return prefix + "/edit";
    }

    /**
     * 修改保存健康档案
     */

    @Log(title = "健康档案", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HealthProfile healthProfile)
    {
        return toAjax(healthProfileService.updateHealthProfile(healthProfile));
    }

    /**
     * 删除健康档案
     */

    @Log(title = "健康档案", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(healthProfileService.deleteHealthProfileByIds(ids));
    }
}
